package homework05_2024_09_20;

/* @Author:zzw
   @Version:1.0
   @DateTime:2024/9/23 9:13
   */
/*
1:输入两个字符串，查找第一个字符串在第二个字符串中出现的次数
比如输入dog和 This dog is a good dog.
则出现了2次。
 */
public class Topic01 {
    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
//        System.out.println("请输入第一个字符串：");
//        String s1 = sc.next();
//        System.out.println("请输入第二个字符串：");
//        String s2 = sc.next();
        String s1 = "abcdacbabcab";
        char[] charArray1 = s1.toCharArray();
        String s2 = "abc";
        char[] charArray2 = s2.toCharArray();
        int appearTimes = 0;
        int index01 = 0;
        int index02 = 0;
        while (index01 < s1.length() && index02 <= s2.length()) {
            if (charArray1[index01] == charArray2[index02]) {
                index01++;
                index02++;
            }
        }
        if (index02 == s2.length()) {
            System.out.println("匹配成功");
        }
        
        System.out.println("查找第一个字符串在第二个字符串中出现的次数为：" + appearTimes);
    }
}
